package com.ctsi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.common.util.Search;
import com.ctsi.core.common.util.$;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.system.entity.SysLog;
import com.ctsi.system.mapper.SysLogMapper;
import com.ctsi.system.service.ISysLogService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统日志表 服务实现类
 * </p>
 *
 * @author wang xiao xiang
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements ISysLogService {

	@Override
	public IPage<SysLog> listPage(SysLog sysLog, Search search) {
		LambdaQueryWrapper<SysLog> queryWrapper = Wrappers.lambdaQuery();
		boolean isTraceId = $.isNotBlank(sysLog.getTraceId());
		if (isTraceId) {
			queryWrapper.eq(SysLog::getTraceId, sysLog.getTraceId());
		}
		boolean isTitle = $.isNotBlank(sysLog.getTitle());
		if (isTitle) {
			queryWrapper.like(SysLog::getTitle, sysLog.getTitle());
		}
		boolean isType = $.isNotBlank(sysLog.getType());
		if (isType) {
			queryWrapper.eq(SysLog::getType, sysLog.getType());
		}
		boolean isIp = $.isNotBlank(sysLog.getIp());
		if (isIp) {
			queryWrapper.like(SysLog::getIp, sysLog.getIp());
		}
		queryWrapper.orderByDesc(SysLog::getCreateTime);
		return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
	}
}
